package lc.栈;

import java.util.Stack;

/**
 * @description: 最小栈
 * @author: qian
 * @createDate: 2021/9/9
 */
public class Math155 {

    /**
     *  push() 把每一个push进来的数都和stackMin进行比较
     *  pop() 要是要pop的值一样就一起pop出
     */

    Stack<Integer> stack;
    Stack<Integer> stackMin;

    public Math155() {
        stack = new Stack<>();
        stackMin = new Stack<>();

    }

    public void push(int val) {
        stack.push(val);
        if(stackMin.isEmpty() || val <= stackMin.peek()) {
            stackMin.push(val);
        }

    }

    public void pop() {

        if(stack.pop().equals(stackMin.peek())) {
            stackMin.pop();
        }

    }

    public int top() {

        return stack.peek();

    }

    public int getMin() {
        return stackMin.peek();
    }
}
